/**
 * \* Created with IntelliJ IDEA.
 * \* User: 冯若航
 * \* Date: 2021/6/18
 * \* Time: 21:20
 * \* To change this template use File | Settings | File Templates.
 * \* Description: 可变参数用类型...定义，可变参数相当于数组类型：
 * \
 */


public class 可变参数 {
    public static void main(String[] args) {
        Group g = new Group();
        g.setNames("Xiao Ming", "Xiao Hong", "Xiao Jun"); // 传入3个String
        g.setNames("Xiao Ming", "Xiao Hong"); // 传入2个String
        g.setNames("Xiao Ming"); // 传入1个String
        g.setNames(); // 传入0个String
    }
}
class Group {
    private String[] names;
    public void setNames(String... names) {
        this.names = names;
    }
}
/**
 * 完全可以把可变参数改写为String[]类型：
 *
 * class Group {
 *     private String[] names;
 *
 *     public void setNames(String[] names) {
 *         this.names = names;
 *     }
 * }
 * 但是，调用方需要自己先构造String[]，比较麻烦。例如：
 *
 * Group g = new Group();
 * g.setNames(new String[] {"Xiao Ming", "Xiao Hong", "Xiao Jun"}); // 传入1个String[]
 * 另一个问题是，调用方可以传入null：
 *
 * Group g = new Group();
 * g.setNames(null);
 */